package rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.servlet;

import java.io.IOException;
import java.util.Collection;

import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.dao.VoznjaDao;
import rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.entitet.Korisnik;
import rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.entitet.Putnik;
import rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.entitet.Vozac;
import rs.ac.uns.ftn.informatika.mbs2.e11031.etaksi.entitet.Voznja;

@SuppressWarnings("serial")
public class PrikazZavrsenihVoznjiKontroler extends HttpServlet {

	@EJB
	private VoznjaDao cVoznjaDao;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {

		HttpSession sesija = req.getSession();

		Collection<Voznja> voznje = null;

		Korisnik korisnik = (Korisnik) sesija.getAttribute("korisnik");
		if (korisnik instanceof Putnik) {
			Putnik putnik = (Putnik) korisnik;
			voznje = cVoznjaDao.zavrsenePutnikoveVoznje(putnik);
		} else {
			Vozac vozac = (Vozac) korisnik;
			voznje = cVoznjaDao.zavrseneVozaceveVoznje(vozac);
		}
		sesija.setAttribute("voznje", voznje);
		getServletContext().getRequestDispatcher(
				"/jsp/prikazZavrsenihVoznji.jsp").forward(req, resp);
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		doGet(req, resp);
	}

}
